﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KBVault.Web.Public.UC
{
    public class PaginationItem
    {
        public int Page { get; set; }
        public string Link { get; set; }
        public bool IsActive { get; set; }
    }
    public partial class KBPagination : System.Web.UI.UserControl
    {
        // Format is 
        // /App/some/limk.apx?page={0}
        public string HrefMask { get; set; }
        public int CurrentPage { get; set; }
        public int MaxPage { get; set; }
        
        public void BindPaginator()
        {
            List<PaginationItem> Paging = new List<PaginationItem>();
            for (int i = 1; i <= MaxPage; i++)
            {
                string href = String.Format(HrefMask, i);
                Paging.Add(new PaginationItem() { Page = i, IsActive = i == CurrentPage, Link = href });
            }
            rptPages.DataSource = Paging;
            rptPages.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(HrefMask))
            {
                pageListContainer.Visible = false;
                return;
            }
            
        }
    }
}